package com.cooper.android.comm;

import java.io.File;

public class FileUtils {
	
	public static void delete(File dirOrFile) {

		if (dirOrFile == null || !dirOrFile.exists())
			return;
		if (dirOrFile.isDirectory()) {
			for (File file : dirOrFile.listFiles()) {
				if (file.isFile())
					file.delete();
				else if (file.isDirectory())
					delete(file);
			}
		}
		dirOrFile.delete();
	}
	
	public static String stringToFileName(String url) {

		String result = url.replace("http://", "c").replaceAll(
				"[\\s\\.\\\\/:\\(\\)@#&$\\-\\[\\]%\'`^!*\"<>|]", "_");
		if (url.length() >= 256) {
			return result.substring(0, 255);
		} else
			return result;
	}
}
